﻿@model BuildContext
@{
    var project = Model.Project;
    var buildTask = Model.Build;
    var schema = Model.GetCurrentSchema();
    var table = Model.GetCurrentTable();
    var entity = Model.GetEntityContext().FindEntity(schema, table);
}
using Util;
using Util.Maps;
using Util.Domains.Repositories;
using Util.Datas.Queries;
using Util.Applications.Trees;
using @(Model.GetServiceName("Dtos"));
using @(Model.GetServiceName("Queries"));
using @(Model.GetServiceName("Abstractions"));

namespace @(Model.GetServiceName("Implements"))
{
    /// <summary>
    /// @entity.Description 服务
    /// </summary>
    public class @(entity.ClassName)Service : TreeServiceBase<@(entity.ClassName), @(entity.ClassName)Dto, @(entity.ClassName)Query@(entity.GetKeyTypeNoContainsGuid())>, I@(entity.ClassName)Service
    {
        /// <summary>
        /// @(entity.Description)仓储
        /// </summary>
        protected I@(entity.ClassName)Repository @(entity.ClassName)Repository { get; set; }
    
        /// <summary>
        /// 初始化一个<see cref="@(entity.ClassName)Service"/>类型的实例
        /// </summary>
        /// <param name="unitOfWork">工作单元</param>
        /// <param name="@(entity.ClassName.ToCamelCase())Repository">@(entity.Description)仓储</param>
        public @(entity.ClassName)Service( I@(project.GetUnitOfWork()) unitOfWork, I@(entity.ClassName)Repository @(entity.ClassName.ToCamelCase())Repository )
            : base( unitOfWork, @(entity.ClassName.ToCamelCase())Repository) {
            @(entity.ClassName)Repository = @(entity.ClassName.ToCamelCase())Repository;
        }

        /// <summary>
        /// 创建查询对象
        /// </summary>
        /// <param name="param">查询参数</param>
        protected override IQueryBase<@(entity.ClassName)> CreateQuery( @(entity.ClassName)Query param ) {
            return new Query< @(entity.ClassName)@(entity.GetKeyTypeNoContainsGuid()) >( param );
        }
    }
}